<template>
  <div class="container">
    <div class="header">
      <h2>
        <i class="el-icon-s-promotion"></i>
        <span>国内机票</span>
      </h2>
    </div>
    <div class="content">
      <div class="left">
        <div class="tabtitle">
          <div
            @click="tab(index)"
            :class="{active:index===currentIndex}"
            v-for="(item,index) in tabList"
            :key="index"
          >{{item}}</div>
        </div>
        <div class="tabcontent">
          <AirForm v-if="currentIndex===0" />
        </div>
      </div>
      <div class="right">
        <img src="http://157.122.54.189:9093/images/pic_sale.jpeg" alt />
      </div>
    </div>
    <div class="server">
      <div class="item" v-for="(item,index) in serverItem" :key="index">
        <i :class="item.icon" :style="[{color:item.color}]"></i>
        {{item.name}}
      </div>
    </div>
    <!-- 特价机票 -->
    <div class="footer">
      <h2>
        <i class="el-icon-s-flag"></i> 特价机票
      </h2>
      <div class="box">
        <div @click="goair(item)" class="item" v-for="(item,index) in imgList" :key="index">
          <img :src="$axios.defaults.baseURL + item.cover" alt />
          <p>
            <span>{{item.departCity}}-{{item.destCity}}</span>
            <span>￥{{item.price}}</span>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import AirForm from '@/components/air/AirForm'
export default {
  components: {
    AirForm
  },
  data() {
    return {
      tabList: ['单程', '往返'],
      currentIndex: 0,
      imgList: [],
      serverItem: [
        {
          name: '100%航协认证',
          icon: 'iconfont iconweibiaoti-_huabanfuben',
          color: 'rgb(64, 158, 255)'
        },
        { name: '出行保证', icon: 'iconfont iconbaozheng', color: 'green' },
        {
          name: '7x24小时服务',
          icon: 'iconfont icondianhua',
          color: 'rgb(64, 158, 255)'
        }
      ]
    }
  },
  created() {
    this.getairsImg()
  },
  methods: {
    tab(i) {
      if (i === 1) {
        return this.$confirm('该功能暂未开发', '提示', {
          confirmButtonText: '确定',
          showCancelButton: false,
          type: 'warning'
        })
      }
      this.currentIndex = i
    },
    async getairsImg() {
      const { data: res } = await this.$axios.get('/airs/sale')
      console.log(res)
      this.imgList = res.data
    },
    goair(item){
      this.$router.push(`/air/flights?departCity=${item.departCity}&departCode=${item.departCode}&destCity=${item.destCity}&destCode=${item.destCode}&departDate=${item.departDate}`)
    }
  }
}
</script>
<style lang="less" scoped>
.container {
  width: 1000px;
  min-width: 1000px;
  margin: 0 auto;
  // background:pink;
  // height:800px;
}
.header {
  margin: 20px 0;
  h2 {
    color: #ffa500;
    font-weight: 300;
  }
}
.content {
  display: flex;
  .left {
    border: 1px solid #eee;
    border-top: none;
    height: 350px;
    padding-bottom: 20px;
    .tabtitle {
      height: 48px;
      background: #eeeeee;
      width: 360px;
      display: flex;
      div {
        flex: 1;
        line-height: 48px;
        text-align: center;
        cursor: pointer;
      }
      .active {
        line-height: 46px;
        background: #fff;
        border-top: 2px solid #ffa500;
      }
    }
    .tabcontent {
      padding-left: 20px;
    }
  }
  .right {
    flex: 1;
    height: 350px;
    margin-left: 20px;
    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
}
.server {
  width: 100%;
  display: flex;
  justify-content: space-between;
  height: 58px;
  background: #f5f5f5;
  align-items: center;
  border: 1px solid #dddddd;
  margin-top: 20px;
  .item {
    flex: 1;
    text-align: center;
    height: 36px;
    border-right: 1px solid #dddddd;
    display: flex;
    align-items: center;
    justify-content: center;
    i {
      font-size: 30px;
      margin-right: 5px;
    }
    &:nth-child(3) {
      border: none;
    }
  }
}
.footer {
  margin-bottom: 40px;
  h2 {
    color: #409eff;
    font-weight: 300;
    margin: 20px 0;
  }
  .box {
    width: 100%;
    border: 1px solid #dddddd;
    height: 182px;
    display: flex;
    justify-content: space-around;
    padding: 20px;
    .item {
      height: 139px;
      width: 225px;
      position: relative;
      // background: red;

      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        cursor: pointer;
      }
      p {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 30px;
        line-height: 30px;
        display: flex;
        justify-content: space-between;
        background: rgba(0, 0, 0, 0.6);
        color: #fff;
        padding: 0 10px;
        font-size: 14px;
      }
    }
  }
}
</style>